import { createRouter, createWebHistory } from 'vue-router'

/**
 * 路由表配置数组（单独抽取：后面扩展后端动态加载）
 *     title?: string; // 菜单标题
         icon?: string; // 菜单图标
         linkTo?: string; // 外链地址
         cache?: boolean; // 是否缓存, 将 name放到include属性上 <keep-alive include="xxx"></keep-alive>
         hidden?: boolean; // 是否左侧菜单中显示，true隐藏/false显示
         isBreadcrumd?: boolean; // 是否显示到面包屑中 默认或true会显示，false不显示

 */
export const dynamicRoutes = [
    {
        path: '/',
        name: 'Layout',
        component: () => import('@/layout/index.vue'),
        redirect: '/home',
        children: [
            {
                path: '/home',
                name: 'Home',
                component: () => import('@/views/home/index.vue'),
                meta: {
                    title: '首页',
                    icon: 'HomeFilled',
                    cache: false,
                    hidden: false
                }
            },

            {
                path: '/system',
                name: 'System',
                redirect: '/system/user',
                meta: {
                    title: '系统管理',
                    icon: 'Setting',
                },
                children: [
                    {
                        path: '/system/param',
                        name: 'Dict',
                        component: () => import('@/views/system/dict/index.vue'),
                        meta: {
                            title: '参数管理',
                            icon: 'Setting',
                            cache: true,
                            hidden: false
                        }
                    },
                    {
                        path: '/system/menu',
                        name: 'SystemMenu',
                        component: () => import('@/views/system/menu/index.vue'),
                        meta: {
                            title: '菜单管理',
                            icon: 'Setting',
                            cache: true,
                            hidden: false
                        }
                    },
                    {
                        path: '/system/role',
                        name: 'SystemRole',
                        component: () => import('@/views/system/role/index.vue'),
                        meta: {
                            title: '角色管理',
                            icon: 'IceCream',
                            cache: true,
                            hidden: false
                        }
                    },
                    {
                        path: '/system/user',
                        name: 'SystemUser',
                        component: () => import('@/views/system/user/index.vue'),
                        meta: {
                            title: '用户管理',
                            icon: 'IceCream',
                            cache: true,
                            hidden: false
                        }
                    },
                ]
            },

            {
                path: '/tenant',
                name: 'Tenant',
                redirect: '/tenant/list',
                meta: {
                    title: '租户管理',
                    icon: 'Setting',
                },
                children: [
                    {
                        path: '/tenant/list',
                        name: 'TenantList',
                        component: () => import('@/views/tenant/list/index.vue'),
                        meta: {
                            title: '租户列表',
                            icon: 'Setting',
                            cache: true,
                            hidden: false
                        }
                    },
                    {
                        path: '/tenant/user',
                        name: 'TenantUser',
                        component: () => import('@/views/tenant/user/index.vue'),
                        meta: {
                            title: '租户账号',
                            icon: 'Setting',
                            cache: true,
                            hidden: false
                        }
                    },
                    {
                        path: '/tenant/role',
                        name: 'TenantRole',
                        component: () => import('@/views/tenant/role/index.vue'),
                        meta: {
                            title: '租户角色',
                            icon: 'Setting',
                            cache: true,
                            hidden: false
                        }
                    },
                ]
            },

            {
                path: '/deviceConfig',
                name: 'DeviceConfig',
                redirect: '/deviceConfig/device',
                meta: {
                    title: '设备配置',
                    icon: 'Goods',
                },
                children: [
                    {
                        path: '/deviceConfig/device',
                        name: 'Device',
                        component: () => import('@/views/device/index.vue'),
                        meta: {
                            title: '设备管理',
                            icon: 'GoodsFilled',
                            cache: true,
                            hidden: false
                        }
                    },
                    {
                        path: '/deviceConfig/collectTemp',
                        name: 'CollectTemp',
                        component: () => import('@/views/collectTemp/index.vue'),
                        meta: {
                            title: '采集项模板配置',
                            icon: 'GoodsFilled',
                            cache: true,
                            hidden: false
                        }
                    },
                    {
                        path: '/deviceConfig/gatewayConfig',
                        name: 'GatewayConfig',
                        component: () => import('@/views/gateway/index.vue'),
                        meta: {
                            title: '硬件配置',
                            icon: 'GoodsFilled',
                            cache: true,
                            hidden: false
                        }
                    },
                ]
            },
        ]
    },
];

/**
 * 全屏显示路由组件，不作用到layout布局主区域渲染出口
 * 这个不通过后端接口返回，系统必须存在的路由
 */
const fullscreenRoutes = [
    {
        path: '/login',
        name: 'Login',
        component: () => import('@/views/login2.vue'),
        meta: {
            title: '登录',
            hidden: true
        }
    },
];

/**
 * 默认路由配置 ：所有用户都可访问的路由，
 * 不需要通过后端接口返回，都需要将下面路由添加到路由表中
 */
export const defaultRoutes = [
    {
        path: '/401',
        name: 'NoPermission',
        component: () => import('@/views/error/401.vue'),
        meta: {
            title: '401页面',
            icon: 'Warning',
            cache: false,
            hidden: true,
        }
    },
    {
        path: '/:path(.*)*', //  404匹配不存在的路由
        name: 'NotFound',
        component: () => import('@/views/error/404.vue'),
        meta: {
            title: '未找到此页面',
            cache: false,
            hidden: true,
        }
    },
]


const router = createRouter({
    //vite.config.js里的base值, hash 模式，路径带#号
    history: createWebHistory(import.meta.env.BASE_URL),
    //routes: dynamicRoutes
    routes: [...defaultRoutes, ...fullscreenRoutes]
})

export default router
